package com.pilipala.controller.common;

import com.pilipala.dto.SearchDTO;
import com.pilipala.result.PageResult;
import com.pilipala.result.Result;
import com.pilipala.service.BlogService;
import com.pilipala.service.UserService;
import com.pilipala.service.VideoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/common/search")
@Tag(name = "搜索相关接口")
@Slf4j
public class SearchController {

    @Autowired
    private BlogService blogService;

    @Autowired
    private VideoService videoService;

    @Autowired
    private UserService userService;
    /**
     * 关于blog的搜索接口
     * @param searchDTO 包括页码、页大小、搜索关键字、排序类型
     * @return 返回分页后的blog
     */
    @GetMapping("/blog")
    @Operation(summary = "关于blog的搜索接口")
    public Result<PageResult> blogSearch(SearchDTO searchDTO){
        log.info("搜索博客中------");
        PageResult pageResult = blogService.search(searchDTO);
        return Result.success(pageResult);
    }

    /**
     * 关于video的搜索接口
     * @param searchDTO 包括页码、页大小、搜索关键字、排序类型
     * @return 返回分页后的video
     */
    @GetMapping("/video")
    @Operation(summary = "关于blog的搜索接口")
    public Result<PageResult> videoSearch(SearchDTO searchDTO){
        log.info("搜索视频中------");
        PageResult pageResult = videoService.search(searchDTO);
        return Result.success(pageResult);
    }

    /**
     * 关于用户的搜索接口
     * @param searchDTO 包括页码、页大小、搜索关键字、排序类型
     * @return 返回分页后的用户
     */
    @GetMapping("/user")
    @Operation(summary = "关于user的")
    public Result<PageResult> userSearch(SearchDTO searchDTO){
        log.info("搜索用户中");
        PageResult pageResult = userService.search(searchDTO);
        return Result.success(pageResult);
    }
}
